package com.woniu.cms.goods.core.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.cms.goods.core.entity.GoodsInventory;
import com.woniu.cms.goods.core.entity.GoodsSummary;
import com.woniu.cms.goods.core.mapper.GoodsSummaryMapper;
import com.woniu.cms.goods.core.service.*;
import com.woniu.cms.goods.core.util.MyDateUtils;
import com.woniu.common.api.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 单项工程月份材料汇总表 服务实现类
 * </p>
 *
 * @author romantic sheep
 * @since 2022-09-20
 */
@Service
public class GoodsSummaryServiceImpl extends ServiceImpl<GoodsSummaryMapper, GoodsSummary> implements IGoodsSummaryService {

    @Autowired
    private GoodsSummaryMapper summaryMapper;

    @Override
    public Result countSummary(String constructTeam, String date, Integer materialType) throws ParseException {
        Date beginDate = MyDateUtils.strToDate(date);
        Date endDate = MyDateUtils.stepMonth(beginDate, 1);
        List<GoodsSummary> list = summaryMapper.countSummary(constructTeam,beginDate,endDate,materialType);
        System.out.println("list = " + list);
        List<GoodsSummary> list2 = summaryMapper.getBeginMoney(constructTeam,beginDate,materialType);
        for (int i=0;i<list.size();i++){
            for (int j=0;j<list2.size();j++){
                if (list.get(i).getConstructTeam().equals(list2.get(j).getConstructTeam())){
                    GoodsSummary goodsSummary = list.get(i);
                    goodsSummary.setBeginMoney(list2.get(j).getBeginMoney());
                    list.set(i,goodsSummary);
                }
            }
        }
        System.out.println("list = " + list);
        Map map=new HashMap();
        map.put("data",list);
        return Result.common(map);
    }


}
